package com.scs.application.modules.upms.security.integration.authenticator;

import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.upms.service.UserService;
import com.scs.application.modules.upms.vo.UserVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

/**
 */
@AllArgsConstructor
public class UsernamePasswordAuthenticator extends AbstractPreparableIntegrationAuthenticator {

    public static final String OAUTH_TYPE = "password";

    @Autowired
    private UserService userService;

    @Override
    public UserVO authenticate(IntegrationAuthentication authentication) {
        return userService.findInfoByLoginKey(authentication.getUsername());
    }

    @Override
    public void prepare(IntegrationAuthentication authentication) {

    }

    @Override
    public boolean support(IntegrationAuthentication authentication) {
        return StringUtils.isBlank(authentication.getAuthType()) || OAUTH_TYPE.equalsIgnoreCase(authentication.getAuthType());
    }

}
